<template>
	<div class="analyze">
		<div class="alert">
			<div class="alert-box">
				<h2>教材册指定小考分析:</h2>
                <i class="el-icon-close close" @click="cancel"></i>
				<el-table :data="dataList" border stripe align="center" class="table" @selection-change="handleSelectionChange">
		            <el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in dataHeaderList" align="center" show-overflow-tooltip></el-table-column>
		            <el-table-column label="分数" width="200px" align="center">
		            	<template scope="scope">
							<el-input placeholder="" icon="edit" v-model="score"></el-input>
		                </template> 
		            </el-table-column>
		        </el-table>
	            <el-button type="info" class="submit" @click="submit">提交</el-button>
	            <el-button type="text" class="cancel" @click="cancel">取消</el-button>
			</div>
		</div>
        <LoadingComponent v-if="isLoading"></LoadingComponent>
	</div>
</template>

<script type="text/javascript">
    import LoadingComponent from 'components/loading'
    export default {
        components: { LoadingComponent },
        props: ['params','type'],
		data () {
			return {
				isLoading:false,
				score: '',
				dataHeaderList: [
					{
						prop: 'className',
                        label: '班级'
					},
					{
						prop: 'teacherName',
                        label: '老师中文名'
					},
					{
						prop: 'teacherEnName',
                        label: '老师英文名'
					},
					{
						prop: 'studengName',
                        label: '学生中文名'
					},
					{
						prop: 'studengEnName',
                        label: '学生英文名'
					}
				],
				dataList: [
					// {
					// 	className:1,
					// 	teacherName:1,
					// 	teacherEnName:3,
					// 	studengName:4,
					// 	studengEnName:5,
					// 	score:100
					// }
				]
			}
		},
		created () {
			console.log(this.params)
			console.log(this.type)
			this.dataList.push({
				className:this.params.row.bjmc,
				teacherName:this.params.row.lszwm,
				teacherEnName:this.params.row.lsywm,
				studengName:this.params.row.xszwm,
				studengEnName:this.params.row.xsywm
			})
			this.score = this.params.row.score;
		},
		methods: {
			demo (a) {
				console.log(a)
			},
			handleSelectionChange () {

			},
			submit () {
				this.isLoading = true;

				if (this.type == 'test') {
					this.axios.get(this.$store.state.api + 'ksscore/updatefs', {
						params: {
							id: this.params.row.id,
							score: this.score
						}
					}).then( res => {
						console.log(res)
						if (res.data.code == 1) {
							this.$emit('close',{type:'testEdit',cancel:false})
						}else{
							this.$emit('close',{type:'testEdit',cancel:false})
						}
					})
				}else{
					this.axios.get(this.$store.state.api + 'zyscore/updatefs', {
						params: {
							id: this.params.row.id,
							score: this.score
						}
					}).then( res => {
						if (res.data.code == 1) {
							this.$emit('close',{type:'testEdit',cancel:false})
						}else{
							this.$emit('close',{type:'testEdit',cancel:false})
						}
					})
				}
				

				this.isLoading = false;
			},
			cancel () {
				this.$emit('close',{type:'testEdit',cancel:true})
			}
		}
	}
</script>

<style lang="less" scoped>
	h2 {
		line-height: 40px;
		text-align: left;
		color:#000;
		font-weight: bold;
	}

	.submit {
		width: 120px;
		margin-top:20px;
	}


</style>